<template>
  <div class="machineMaintainProject">
    <DFPageList ref="dfPageListRef" :pageOptions="pageOptions" />
  </div>
</template>

<script lang="ts" setup name="machineMaintainProject">
  import { useMixins } from '@/hooks/useMixins';
  import {
    pageMachineMaintainProject,
    delMachineMaintainProject,
    exportMachineMaintainProject,
  } from '@/api/base/machineMaintainProject';
  import { listMachine } from '@/api/base/machine';

  import lang from './lang';

  const { loadLangFn } = useMixins();

  const machineList = ref([]);

  const beforeResetFn = () => {};

  const afterResetFn = () => {};

  loadLangFn(lang);

  const pageOptions = {
    searchForm: {
      formSchemas: [
        {
          label: 'machineName',
          prop: 'machineCode',
          component: 'NSelect',
          options: machineList,
        },
      ],
      beforeResetFn,
      afterResetFn,
    },
    table: {
      hasSelection: true,
      // importTemplateType: '10',
      // importUrl: '/crm/crmTblTestStandards/importExcel',
      // rowKey: 'name',
      columns: [
        {
          label: 'machineCode',
        },
        {
          label: 'machineName',
        },
        {
          label: 'machineModel',
        },
      ],
      action: {
        columns: [
          {
            label: 'check',
            hump: true,
          },
          {
            label: 'edit',
            hump: true,
          },
          {
            label: 'copy',
            hump: true,
          },
          {
            label: 'delete',
          },
        ],
      },
      operaColumn: [
        {
          label: 'add',
          hump: true,
        },
        // {
        //   label: 'delete',
        // },
        // {
        //   label: 'import',
        // },
        {
          label: 'export',
        },
      ],
      requestFn: pageMachineMaintainProject,
      delRequestFn: delMachineMaintainProject,
      exportRequestFn: exportMachineMaintainProject,
    },
  };

  // 发送请求获取设备名称数据
  const initFn = async () => {
    getMachineNameFn();
  };

  // 获取设备名称
  const getMachineNameFn = async () => {
    const res = await Promise.all([listMachine()]);
    const [list1] = res;

    machineList.value =
      list1?.data.map((item) => ({
        label: item.machineName,
        value: item.machineCode,
      })) || [];
  };
  initFn();
</script>
